package com.example.qt.ptplatform.controller;

import com.example.qt.ptplatform.service.impl.SeedServiceImpl;
import com.example.qt.ptplatform.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping(value = "seed")
public class SeedController {

    @Autowired
    private SeedServiceImpl seedService;

    // 接口：处理添加种子记录的请求
    @RequestMapping(value = "/addSeed", method = RequestMethod.POST)
    public JsonResult addSeed(@RequestParam("file") MultipartFile file,
                              @RequestParam("user_id") int userId,
                              @RequestParam("title") String title,
                              @RequestParam("description") String description,
                              @RequestParam("tags") String tags,
                              @RequestParam("category") String category) {
        try {
            SeedServiceImpl.UploadResult result = seedService.addSeed(file, userId, title, description, tags, category);
            // 封装积分为一个Map或对象（推荐）
            Map<String, Object> data = new HashMap<>();
            data.put("points", result.getEarnedPoints());
            return JsonResult.success(200, "种子上传成功", data);
        } catch (Exception e) {
            // 返回失败结果
            return JsonResult.error("添加种子失败", e.getMessage());
        }
    }


}


